package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * 排序字符串
 */
public class SortListDemo3 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("苍老师");
        list.add("传奇");
        list.add("小泽老师");
        System.out.println(list);
//        Collections.sort(list);

//        Collections.sort(list, new Comparator<String>() {
//            public int compare(String o1, String o2) {
//                return o1.length()-o2.length();
//            }
//        });
        //从小到大
//        Collections.sort(list, (o1,o2)->o1.length()-o2.length());
        //从大到小(反过来减)
        Collections.sort(list, (o1,o2)->o2.length()-o1.length());
        System.out.println(list);


    }
}



